package bjtu.pinet.service;

import bjtu.pinet.common.ParsingResult;
import bjtu.pinet.common.pinetpacket.HttpPacket;
import bjtu.pinet.common.pinetpacket.IPv4Packet;
import org.onlab.packet.TCP;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * author:chushuai
 * date:2021.2.13
 */
public class IPToNDNTurnServiceLocalImpl implements IPToNDNTurnService{
    private final Logger log = LoggerFactory.getLogger(getClass());
    @Override
    public Boolean ipToNDN(String ndnName) {
        String cachedNDNNameLabel = "bjtu";
        if(ndnName.contains(cachedNDNNameLabel)){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public String getNDNName(ParsingResult parsingResult) {
        IPv4Packet iPv4Packet = (IPv4Packet) parsingResult.getPacketParsingResult();
        TCP tcpPacket  = (TCP)iPv4Packet.getPayload();
        log.info("---------------------tcppacket--------------------"+tcpPacket);
        HttpPacket httpPacket = HttpPacket.deserialize(tcpPacket.getPayload().serialize());
        log.info("---------------------httpPacket--------------------"+httpPacket);
        String ndnName = httpPacket.getPath();
        return ndnName;
    }
}
